//
//  EmergencyTableViewCell.m
//  DanaKreditLoan
//
//  Created by ZhengChengFeng on 2024/10/23.
//

#import "EmergencyTableViewCell.h"

@implementation EmergencyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        self.backV = [[UIView alloc] init];
        [self.contentView addSubview:self.backV];
        [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.top.equalTo(self.contentView.mas_top);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        self.backV.layer.cornerRadius = 14;
        self.backV.layer.masksToBounds = YES;
        
        self.topNameLab = [UILabel createLabel:[UIFont fontWithName:kFuturaBold size:13] color:kBlackColor];
        [self.backV addSubview:self.topNameLab];
        [self.topNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(15);
            make.top.equalTo(self.backV.mas_top);
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.height.equalTo(@50);
        }];
        
        self.whiteV1 = [[UIView alloc] init];
        [self.backV addSubview:self.whiteV1];
        [self.whiteV1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(15);
            make.top.equalTo(self.topNameLab.mas_bottom);
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.height.equalTo(@83);
        }];
        self.whiteV1.layer.cornerRadius = 14;
        self.whiteV1.layer.masksToBounds = YES;
        self.whiteV1.layer.borderColor = [UIColor colorWithHexString:@"#EFEFEF"].CGColor;
        self.whiteV1.layer.borderWidth = 1;
        
        self.whiteV2 = [[UIView alloc] init];
        [self.backV addSubview:self.whiteV2];
        [self.whiteV2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(15);
            make.top.equalTo(self.whiteV1.mas_bottom).offset(15);
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.height.equalTo(@83);
        }];
        self.whiteV2.layer.cornerRadius = 14;
        self.whiteV2.layer.masksToBounds = YES;
        self.whiteV2.layer.borderColor = [UIColor colorWithHexString:@"#EFEFEF"].CGColor;
        self.whiteV2.layer.borderWidth = 1;
        
        self.whiteV1.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap1)];
        [self.whiteV1 addGestureRecognizer:tap1];
        
        self.whiteV2.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap2)];
        [self.whiteV2 addGestureRecognizer:tap2];
        
        
        
        
        
        self.ic1 = [[UIImageView alloc] init];
        [self.whiteV1 addSubview:self.ic1];
        [self.ic1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.whiteV1.mas_right);
            make.top.equalTo(self.whiteV1.mas_top);
            make.width.equalTo(@46);
            make.height.equalTo(@58);
        }];
        self.titleLab1 = [UILabel createLabel:[UIFont fontWithName:kFutura size:15] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        [self.whiteV1 addSubview:self.titleLab1];
        [self.titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.whiteV1.mas_left).offset(15);
            make.right.equalTo(self.whiteV1.mas_right).offset(-5);
            make.top.equalTo(self.whiteV1.mas_top).offset(15);
            make.height.equalTo(@20);
        }];
        
        self.textFiled1 = [[UITextFieldHelper alloc] init];
        self.textFiled1.textColor = kBlackColor;
        self.textFiled1.font = [UIFont fontWithName:kFutura size:15];
        self.textFiled1.delegate = self;
        [self.whiteV1 addSubview:self.textFiled1];
        [self.textFiled1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLab1.mas_left);
            make.right.equalTo(self.whiteV1.mas_right).offset(-5 - 11);
            make.bottom.equalTo(self.whiteV1.mas_bottom);
            make.top.equalTo(self.titleLab1.mas_bottom);
        }];
       
        [self.textFiled1 addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        
        self.arrowIc1 = [[UIImageView alloc] init];
        [self.whiteV1 addSubview:self.arrowIc1];
        [self.arrowIc1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@11);
            make.height.equalTo(@8);
            make.right.equalTo(self.whiteV1.mas_right).offset(-5);
            make.centerY.equalTo(self.textFiled1.mas_centerY);
        }];
        
        
        
        
        self.ic2 = [[UIImageView alloc] init];
        [self.whiteV2 addSubview:self.ic2];
        [self.ic2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.whiteV2.mas_right);
            make.top.equalTo(self.whiteV2.mas_top);
            make.width.equalTo(@46);
            make.height.equalTo(@58);
        }];
        self.titleLab2 = [UILabel createLabel:[UIFont fontWithName:kFutura size:15] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        [self.whiteV2 addSubview:self.titleLab2];
        [self.titleLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.whiteV2.mas_left).offset(15);
            make.right.equalTo(self.whiteV2.mas_right).offset(-5);
            make.top.equalTo(self.whiteV2.mas_top).offset(15);
            make.height.equalTo(@20);
        }];
        
        self.textFiled2 = [[UITextFieldHelper alloc] init];
        self.textFiled2.textColor = kBlackColor;
        self.textFiled2.font = [UIFont fontWithName:kFutura size:15];
        self.textFiled2.delegate = self;
        [self.whiteV2 addSubview:self.textFiled2];
        [self.textFiled2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLab2.mas_left);
            make.right.equalTo(self.whiteV2.mas_right).offset(-5 - 11);
            make.bottom.equalTo(self.whiteV2.mas_bottom);
            make.top.equalTo(self.titleLab2.mas_bottom);
        }];
       
        [self.textFiled2 addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        
        self.arrowIc2 = [[UIImageView alloc] init];
        [self.whiteV2 addSubview:self.arrowIc2];
        [self.arrowIc2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@11);
            make.height.equalTo(@8);
            make.right.equalTo(self.whiteV2.mas_right).offset(-5);
            make.centerY.equalTo(self.textFiled2.mas_centerY);
        }];
        
        
        
    }
    return self;
}

- (void)textFieldDidChange:(UITextField *) textField{
    NSString *textString = esString(textField.text);
}

- (void)clickTap1{
    if (_clickTap1Block) {
        _clickTap1Block(_model);
    }
}

- (void)clickTap2{
    if (_clickTap2Block) {
        _clickTap2Block(_model);
    }
}

- (void)setModel:(EmergencyModel *)model{
    _model = model;
    self.textFiled1.userInteractionEnabled = NO;
    self.textFiled2.userInteractionEnabled = NO;
    
    self.ic1.image = [UIImage imageNamed:@"icon_rl"];
    self.arrowIc1.image = [UIImage imageNamed:@"icon_idcard8"];
    
    self.ic2.image = [UIImage imageNamed:@"icon_rl"];
    self.arrowIc2.image = [UIImage imageNamed:@"icon_idcard8"];
    
    self.titleLab1.text = ASLocalizedString(@"Emergency1Str");
    self.titleLab2.text = ASLocalizedString(@"Emergency3Str");
    
    
    self.textFiled1.placeholder = ASLocalizedString(@"Emergency2Str");
    self.textFiled2.placeholder = ASLocalizedString(@"Emergency4Str");
    
    self.textFiled1.text = esString(model.relatedName);
    if (!PMStringIsEmpty(model.hydrogen) && !PMStringIsEmpty(model.quinine)) {
        self.textFiled2.text = [NSString stringWithFormat:@"%@-%@",esString(model.hydrogen),esString(model.quinine)];
    }
    else{
        self.textFiled2.text = @"";
    }
    
    NSMutableAttributedString *placeholderString1 = [[NSMutableAttributedString alloc] initWithString:self.textFiled1.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EFEFEF"]}];
    self.textFiled1.attributedPlaceholder = placeholderString1;
    
    NSMutableAttributedString *placeholderString2 = [[NSMutableAttributedString alloc] initWithString:self.textFiled2.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EFEFEF"]}];
    self.textFiled2.attributedPlaceholder = placeholderString2;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
